package com.itheima.tlias.service.impl;

import com.itheima.tlias.mapper.EmpMapper;
import com.itheima.tlias.model.dto.EmpQueryDTO;
import com.itheima.tlias.model.entity.Emp;
import com.itheima.tlias.model.response.PageResult;
import com.itheima.tlias.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Lee
 * @created 2024/4/8
 * @describtion
 */
@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;

    /**
     * 查询员工信息并进行分页处理
     * @param dto 查询条件
     * @return
     */
    @Override
    public PageResult<Emp> list(EmpQueryDTO dto) {
        // 分页参数处理
        dto.setPage((dto.getPage() - 1) * dto.getPageSize());
        // 查询满足条件的总记录数
        Long total = empMapper.selectCount(dto);
        // 查询当前页数据
        List<Emp> empList = empMapper.selectByPage(dto);
        // 结果封装返回
        return new PageResult<Emp>(total, empList);
    }
}
